﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace RockBus.Monitoring.DataContracts.Configuration
{
    /// <summary>
    /// Holds the configuration that specifies how to collect and transmit performance counter values.
    /// </summary>
    [DataContract(Namespace = NamespaceConstants.MonitoringNamespace)]
    public class MonitoringConfiguration
    {
        /// <summary>
        /// The interval (in milliseconds) on which the performance counter values should be collected.
        /// </summary>
        [DataMember(IsRequired = false)]
        public int CollectionIntervalMs { get; set; }

        /// <summary>
        /// The number of performance counter values to use for calculation of the aggregated values (see AggregationType). I.e. if BufferSize = 0 and AggregationType = MovingAverage, a MovingAverage will be calculated over the last 20 performance counter values.
        /// </summary>
        [DataMember(IsRequired = false)]
        public int BufferSize { get; set; }

        /// <summary>
        /// The array of PerformanceCounterConfiguration specifying how to collect the performance counter values.
        /// </summary>
        [DataMember(IsRequired = false)]
        public IEnumerable<PerformanceCounterConfigurationBase> PerformanceCounterConfigurations { get; set; }

        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.AppendLine(string.Format("CollectionIntervalMs: {0}", this.CollectionIntervalMs));
            sb.AppendLine(string.Format("BufferSize: {0}", this.BufferSize));
            if (null != this.PerformanceCounterConfigurations)
            {
                foreach (var pcc in this.PerformanceCounterConfigurations)
                {
                    sb.AppendLine(pcc.ToString());
                }
            }
            return sb.ToString();
        }
    }
}